package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mapper.OmsOrderReturnReasonMapper;
import com.itheima.pojo.OmsOrderReturnReason;
import com.itheima.vo.PageResultVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class OmsOrderReturnReasonImpl implements OmsOrderReturnReasonApi {
    @Autowired
    private OmsOrderReturnReasonMapper mapper;

    @Override
    public List<OmsOrderReturnReason> getAllReason() {
        List<OmsOrderReturnReason> reasons = mapper.selectList(new LambdaQueryWrapper<>());
        return reasons;
    }

    @Override
    public void create(OmsOrderReturnReason reason) {
        mapper.insert(reason);
    }

    @Override
    public List<OmsOrderReturnReason> getReasonByids(List<Long> ids) {
        List<OmsOrderReturnReason> returnReasons = mapper.selectList(new LambdaQueryWrapper<OmsOrderReturnReason>()
                .in(OmsOrderReturnReason::getId, ids));
        return returnReasons;
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        for (Long id : ids) {
            mapper.deleteById(id);
        }
    }

    @Override
    public PageResultVo list(Integer pageNum, Integer pageSize) {
        Page<OmsOrderReturnReason> page = new Page<>(pageNum, pageSize);
        Page<OmsOrderReturnReason> page1 = mapper.selectPage(page, new LambdaQueryWrapper<>());
        PageResultVo vo = new PageResultVo();
        vo.setList(page1.getRecords());
        vo.setTotal((int) page1.getTotal());
        vo.setTotalPages((int) page1.getPages());
        vo.setPageNum(pageNum);
        vo.setPageSize(pageSize);
        return vo;
    }

    @Override
    public OmsOrderReturnReason findByid(Long ids) {
        OmsOrderReturnReason reason = mapper.selectById(ids);
        return reason;
    }

    @Override
    public void updateStatus(Integer ids, Integer status) {
        OmsOrderReturnReason reason=new OmsOrderReturnReason();
        reason.setStatus(status);
        mapper.update(reason,new LambdaQueryWrapper<OmsOrderReturnReason>().eq(OmsOrderReturnReason::getId,ids));
    }

    @Override
    public void updateByid(OmsOrderReturnReason reason) {
        mapper.updateById(reason);
    }
}
